<template>
  <div class="charging">
    <div class="topNav">
      <TopNav></TopNav>
    </div>
    <div class="title">
      <span>{{ title }}</span>
    </div>
    <router-view
      @getChargeData="getChargeData"
      :chargeData="chargeData"
      v-if="isRouterAlive"
      @refresh="refresh"
    ></router-view>
  </div>
</template>

<script>
import TopNav from "../components/TopNav.vue";

export default {
  name: "Charge",
  components: {
    TopNav,
  },
  data() {
    return {
      title: "计费管理",
      chargeData: [],
      isRouterAlive: true,
    };
  },
  methods: {
    //获取收费规则数据
    getChargeData(value) {
      this.chargeData = value;
    },
    refresh() {
      this.isRouterAlive = false;
      this.$nextTick(() => {
        this.isRouterAlive = true;
      });
    },
  },
  watch: {
    $route: {
      handler: function (val, oldVal) {
        const path = val.path;
        if (path === "/charging/edit") {
          this.title = "编辑";
        } else if (path === "/charging/add") {
          this.title = "添加";
        } else {
          this.title = "计费管理";
        }
      },
      deep: true,
    },
  },
};
</script>

<style scoped>
.charging {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  background-color: #ffffff;
}
.topNav {
  height: 11vh;
  width: 100%;
  border-bottom: 1px solid #e2e3e4;
}
.title {
  width: 80%;
  height: 7vh;
  padding: 10px 0 0 30px;
  line-height: 4vh;
  text-align: left;
  font-size: 1.2rem;
  font-weight: 600;
}
.title span {
  display: inline-block;
  width: 80%;
  height: 60%;
  padding: 0px 20px;
  border-left: 5px solid #409eff;
}
</style>